package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 添加联系人（好友）
     * 请求方式：Post  contacts
     * 请求参数：Map ： userId(当前用户添加的好友ID)
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        Long friendId = Long.valueOf(map.get("userId").toString());
        messagesService.addContacts(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询列席人列表（好友）
     *  Get contacts
     */
    @GetMapping("/contacts")
    public ResponseEntity findContacts(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pagesize) {
       PageResult pr =  messagesService.findContacts(page,pagesize);
       return ResponseEntity.ok(pr);
    }

    /**
     * 根据环信id。查询用户信息
     * get : userInfo
     * 参数：huanxinId
     * 返回值：userInfoVo
     */
    @GetMapping("/userinfo")
    public ResponseEntity userInfo(String huanxinId) {
        UserInfoVo userInfo = messagesService.findByHuanxinId(huanxinId);
        return ResponseEntity.ok(userInfo);
    }
}
